trigger setmanagerforhcpedu on HCPEducation__c (before update,before insert) {
    list<id> idl=new list<id>();
    list<HCPEducation__c> hcpedul=new list<HCPEducation__c>();
 //   list<HCPEducation__c> heupd=new list<HCPEducation__c>();
    list<user> u=new list<user>();
    list<id> uid=new list<id>();
    
     for(HCPEducation__c he:trigger.new){
         idl.add(he.id);
         uid.add(he.ownerid);
     }
     
     
 //   hcpedul=[select id,manager__c,ownerid from HCPEducation__c where id in:idl];
    u=[select id,managerid from user where id in:uid];
    
    if(system.trigger.isupdate){
    for(HCPEducation__c het:trigger.new){
        if(system.trigger.oldmap.get(het.id).ownerid != het.ownerid){
      //      for(HCPEducation__c he:hcpedul){
                for(user ul:u){
                    if(ul.id==het.ownerid){   // && he.id==het.id){
                        het.manager__c=ul.managerid;
  //                      heupd.add(het);
                    }
     //           }
              }  
            }
        }
    }else if(system.trigger.isinsert){
        for(HCPEducation__c het:trigger.new){
  //            for(HCPEducation__c he:hcpedul){
                for(user ul:u){
                    if(ul.id==het.ownerid){    // && he.id==het.id){
                       het.manager__c=ul.managerid;
   //                     heupd.add(het);
                    }
      //          }
              }  
            }
        }
//        if(heupd.size()>0){update heupd;}

    
     
   
   
   
   
   
   
   
   /*  for(HCPEducation__c hcp:trigger.new){
       if(system.trigger.isupdate){
            if(system.trigger.oldmap.get(hcp.id).ownerid != hcp.ownerid){
                user u=[select id,managerid from user where id=: hcp.OwnerId];
                HCPEducation__c hl=[select id,manager__c from HCPEducation__c where id=:hcp.id];
                    if(u.managerid<>null){
                        HCPEducation__c h=hl;
                        h.manager__c=u.managerid;
                        update h;
                        }
                    }
             }else if(system.trigger.isinsert){
                     user u=[select id,managerid from user where id=: hcp.OwnerId];
                HCPEducation__c hl=[select id,manager__c from HCPEducation__c where id=:hcp.id];
                    if(u.managerid<>null){
                        HCPEducation__c h=hl;
                        h.manager__c=u.managerid;
                        update h;
                        }
             }
        }*/
}